<?php
/**
 * Created by PhpStorm.
 * User: jungshen
 * Date: 2019/3/1
 * Time: 14:30
 */

namespace app\api2\controller\member;


use app\api\controller\BasicUserApi;
use app\api\service\MemberService;
use app\api2\Service\InquiryService;
use service\DataService;
use think\Db;
use think\Exception;

/**
 * 询价控制器
 * Class Inquiry
 * @package app\api2\controller\member
 */
class Inquiry extends BasicUserApi
{
    /**
     * 发布询价
     * @return \think\response\Json
     */
    function release(){
        if($this->request->isPost()) {
            /**
             * //quotation_detail json数据可解析出下面这种格式
             * quotation_detail[0]['image']//工种
             * quotation_detail[0]['number']//人数
             * quotation_detail[0]['images']//工价/天
             */
            $post = $this->request->only(
                ['goods_type_ids', 'min_credit','title',
                    'grab_sheet_end_time',//抢单结束时间
                    'auth', 'attr','desc', 'voice', 'quotation_detail',//报价明细
                    'back_type', 'mobile', 'back_hour']
                , 'post');
            //处理数据
            $post['grab_sheet_end_time']=strtotime($post['grab_sheet_end_time']);
            if($post['quotation_detail']){
                $quotation_detail=json_decode($post['quotation_detail'],true);
                $quotation_detail_deal=[];

                foreach ($quotation_detail as $k=>&$v){
                    if($v['number']<1){
                        return json(['msg'=>'报价项目有误'],500);
                    }
                    $quotation_detail_deal[$k+1]=$quotation_detail[$k];
                }
                $post['quotation_detail']=json_encode($quotation_detail_deal);
            }

            $post['mid']=UID;
            $post['status']=0;
            $post['addtime']=time();
            $post['order_sn']=DataService::createSequence(10,'INQUIRY');
            Db::name('inquiry')
                ->insert($post);
            return json(['msg'=>'发布成功,请等待审核'],200);
        }
    }

    /**
     * 正在抢单的列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function lists(){
        $page_size=$this->request->get('page_size',10);
        $page_now=$this->request->get('page_now',1);
        //查询我抢了单的
        $inquiry_offer=Db::name('inquiry_offer')
            ->where('mid',UID)
            ->where('status','<>',0)
            ->column('inquiry_id');

        $db=Db::name('inquiry')
            ->where('mid','<>',UID)
            //->where('grab_sheet_end_time','>',time())//这个条件应该加上
            ->where('status','>',0);
//            ->where('status',1);
        if($inquiry_offer){
            $db->where('id','not in',$inquiry_offer);
        }
        $list=$db->field('id,mid,desc,addtime,grab_sheet_end_time,back_type,quotation_detail,status,title')
            ->page($page_now,$page_size)
            ->order('status,id desc')
            ->select();
        foreach ($list as $k=>&$v){
            if($v['status']==1&&$v['grab_sheet_end_time']<=time()){
                $v['status']=2;
            }
            $v['addtime']=date('Y/m/d',$v['addtime']);
            $v['grab_sheet_end_time']=date('Y/m/d H',$v['grab_sheet_end_time']);
            $v['quotation_detail']=json_decode($v['quotation_detail'],true);
        }
        return json(['msg'=>'success','data'=>$list],200);
    }

    /**
     * 抢单详情(抢单的时候查看的详情)
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function view(){
        //询价信息ID
        $inquiry_id=$this->request->get('inquiry_id');
        $inquiry=Db::name('inquiry')
            ->where('id',$inquiry_id)
            ->where('status',1)
            ->where('mid','<>',UID)
            ->field('id,mid,desc,addtime,grab_sheet_end_time,back_type,quotation_detail,status,attr,vip_money,money,title,voice,order_sn')
            ->find();
        if(!$inquiry){
            return json(['msg'=>'未查询到数据'],500);
        }
        $inquiry['addtime']=date('Y/m/d H:i:s',$inquiry['addtime']);
        $inquiry['grab_sheet_end_time']=date('Y/m/d H:i:s',$inquiry['grab_sheet_end_time']);
        $inquiry['quotation_detail']=(array)json_decode($inquiry['quotation_detail'],true);
//        dump($inquiry['quotation_detail']);
        $inquiry['author']=Db::name('store_member')
            ->where('id',$inquiry['mid'])->field('nickname,type,id')->find();
        //判断抢单人是否是VIP
        $viewer=Db::name('store_member')
            ->where('id',UID)->field('type,id')->find();
        if($viewer['type']>0){
            //判断是否是超级会员
            $isSuper=MemberService::isSuper($viewer);
            if($isSuper) {
                $inquiry['order_money']=0;
            }else{
                //VIP
                $inquiry['order_money']=$inquiry['vip_money'];
            }
        }else{
            $inquiry['order_money']=$inquiry['money'];
        }
        return json(['msg'=>'success','data'=>$inquiry],200);
    }

    /**
     * 单项浏览
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function view_single(){
        $index=$this->request->get('index',1);
        $inquiry_id=$this->request->get('inquiry_id');
        $inquiry=Db::name('inquiry')
            ->where('id',$inquiry_id)
            ->where('status',1)
            ->where('mid','<>',UID)
            ->field('id,quotation_detail')
            ->find();
        if(!$inquiry){
            return json(['msg'=>'未查询到数据'],500);
        }
        $quotation_detail=json_decode($inquiry['quotation_detail'],true);
        $inquiry['curr_quotation_detail']=$quotation_detail[$index];
        $inquiry['curr_quotation_detail']['images']=explode('|',$inquiry['curr_quotation_detail']['images']);
        //是否还有下一项
        if(isset($quotation_detail[$index+1])){
            $data['next_index']=$index+1;
        }else{
            $data['next_index']=0;
        }
        $data['inquiry']=$inquiry;
        return json(['msg'=>'success','data'=>$data],200);
    }

    /**
     * 单项报价
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function offer_single(){
        $index=$this->request->get('index');
        $price=$this->request->get('price');
        $inquiry_id=$this->request->get('inquiry_id');
        //不能给自己发布的报价 不能重复报价
        $inquiry=Db::name('inquiry')
            ->where('id',$inquiry_id)
            ->field('mid,min_credit,auth')
            ->find();
        $inquiry['auth']=explode(',',$inquiry['auth']);

        if(UID==$inquiry['mid']){
            return json(['msg'=>'您不能给自己报价'],500);
        }
        $member=Db::name('store_member')
            ->alias('m')
            ->leftJoin('authentication a','a.mid=m.id and a.status=1')
            ->leftJoin('earnest e','e.mid=m.id and e.status=1')
            ->where('m.id',UID)
            ->field('m.type,m.credit,m.real_address,a.id authentication_id,e.id earnest_id')
            ->find();
        if($inquiry['min_credit']>$member['credit']){
            return json(['msg'=>'您的信用分不足'],500);
        }
        if(in_array(5,$inquiry['auth'])&&intval($member['authentication_id'])<1){
            return json(['msg'=>'该订单需要实名认证'],500);
        }
        if(in_array(6,$inquiry['auth'])&&$member['real_address']!=1){
            return json(['msg'=>'该订单需要实地认证'],500);
        }
        if(in_array(4,$inquiry['auth'])&&intval($member['earnest_id'])<1){
            return json(['msg'=>'该订单需要缴纳保证金'],500);
        }
        if(in_array(1,$inquiry['auth'])&&$member['type']==0){
            return json(['msg'=>'该订单需要入驻超级会员'],500);
        }

        //查询是否报价了
        $inquiry_offer=Db::name('inquiry_offer')
            ->where('mid',UID)
            ->where('inquiry_id',$inquiry_id)
            ->find();
        if(!$inquiry_offer){
            //未报价 新增报价明细
            $quotation_offer[$index]=$price;
            $io_data['mid']=UID;
            $io_data['inquiry_id']=$inquiry_id;
            $io_data['quotation_offer']=json_encode($quotation_offer);
            $io_data['addtime']=time();
            $io_data['status']=0;
            $io_data['order_sn']=DataService::createSequence(10,'INQUIRY');
            Db::name('inquiry_offer')->insert($io_data);
        }else{
            if($inquiry_offer['status']==0){
                //未提交 更新报价
                $quotation_offer=json_decode($inquiry_offer['quotation_offer'],true);
                $quotation_offer[$index]=$price;
                Db::name('inquiry_offer')->where('id',$inquiry_offer['id'])->setField('quotation_offer',json_encode($quotation_offer));
            }else{
                //已报价
                return json(['msg'=>'请不要重复报价'],500);
            }
        }
        return json(['msg'=>'success'],200);

    }

    /**
     * 获取整体报价信息
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function offer_view(){
        $inquiry_id=$this->request->get('inquiry_id');
        $inquiry=Db::name('inquiry')
            ->alias('i')
            ->join('store_member m','m.id=i.mid')
            ->where('i.id',$inquiry_id)
            ->where('i.status',1)
            //->where('i.mid','<>',UID)
            ->field('i.id,i.quotation_detail,i.addtime,i.grab_sheet_end_time,i.back_type,m.nickname,m.phone,m.type member_type,i.mid,i.vip_money,i.money')
            ->find();
        if(!$inquiry){
            return json(['msg'=>'未查询到数据'],500);
        }
        $inquiry['nickname']=InquiryService::deal_nickname($inquiry['nickname'],$inquiry['member_type'],$inquiry['mid']);

        $inquiry['addtime']=date('Y/m/d H:i:s',$inquiry['addtime']);
        $inquiry['quotation_detail']=json_decode($inquiry['quotation_detail'],true);

        $inquiry['author']=Db::name('store_member')
            ->where('id',$inquiry['mid'])->field('nickname,type,id')->find();
        //判断抢单人是否是VIP
        $viewer=Db::name('store_member')
            ->where('id',UID)->field('type,id')->find();
        if($viewer['type']>0){
            //判断是否是超级会员
            $isSuper=MemberService::isSuper($viewer);
            if($isSuper) {
                $inquiry['order_money']=0;
            }else{
                //VIP
                $inquiry['order_money']=$inquiry['vip_money'];
            }
        }else{
            $inquiry['order_money']=$inquiry['money'];
        }

        //查询报价信息
        $quotation_offer=Db::name('inquiry_offer')
            ->where('inquiry_id',$inquiry['id'])
            ->where('mid',UID)
            ->value('quotation_offer');
        $inquiry['offer']=json_decode($quotation_offer,true);
        return json(['msg'=>'success','data'=>$inquiry],200);
    }

    /**
     * 确认竞价
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    function offer(){
        $post=$this->request->only(['inquiry_id','quotation_detail',//quotation_detail : json 第几项 多少钱
            'tax','tax_ratio','freight','install_fee','time_limit','total_price'],'post');
        /*if(!is_numeric($post['freight'])){
            return json(['msg'=>'运输费不能为空'],500);
        }
        if(!is_numeric($post['install_fee'])){
            return json(['msg'=>'安装费不能为空'],500);
        }*/
        if(!is_numeric($post['tax'])){
            return json(['msg'=>'税费不能为空'],500);
        }
        //不能给自己发布的报价 不能重复报价
        $inquiry=Db::name('inquiry')
            ->where('id',$post['inquiry_id'])
            ->field('mid,min_credit,auth,vip_money,money,grab_sheet_end_time')
            ->find();
        $inquiry['auth']=explode(',',$inquiry['auth']);

        if($inquiry['grab_sheet_end_time']<=time()){
            return json(['msg'=>'该订单已过期'],500);
        }
        if(UID==$inquiry['mid']){
            return json(['msg'=>'您不能给自己报价'],500);
        }
        $member=Db::name('store_member')
            ->alias('m')
            ->leftJoin('authentication a','a.mid=m.id and a.status=1')
            ->leftJoin('earnest e','e.mid=m.id and e.status=1')
            ->where('m.id',UID)
            ->field('m.type,m.credit,m.real_address,a.id authentication_id,e.id earnest_id,m.money,m.id')
            ->find();

        if($member['type']!=2){
            return json(['msg'=>'请先入驻成为供应商'],500);
        }else{
            //判断是否过期
            $supplier_info=Db::name('supplier_info')
                ->where('mid',$member['id'])
                ->field('expiry_time')->find();
            if($supplier_info['expiry_time']<time()){
                return json(['msg'=>'您的供应商会员已过期,请先续费'],500);
            }

            //判断是否是超级会员
            $isSuper=MemberService::isSuper($member);
            if($isSuper) {
                $real_money=0;
            }else{
                //VIP
                $real_money=$inquiry['vip_money'];
            }
            //判断余额
            if($member['money']<$real_money){
                //VIP
                return json(['msg'=>'您的余额不足'],500);
            }

        }
        //判断资格
        if($inquiry['min_credit']>$member['credit']){
            return json(['msg'=>'您的信用分不足'],500);
        }
        if(in_array(5,$inquiry['auth'])&&intval($member['authentication_id'])<1){
            return json(['msg'=>'该订单需要实名认证'],500);
        }
        if(in_array(6,$inquiry['auth'])&&$member['real_address']!=1){
            return json(['msg'=>'该订单需要实地认证'],500);
        }
        if(in_array(4,$inquiry['auth'])&&intval($member['earnest_id'])<1){
            return json(['msg'=>'该订单需要缴纳保证金'],500);
        }
        if(in_array(1,$inquiry['auth'])&&$member['type']==0){
            return json(['msg'=>'该订单需要入驻超级会员'],500);
        }

        //查询是否报价了
        $inquiry_offer=Db::name('inquiry_offer')
            ->where('mid',UID)
            ->where('inquiry_id',$post['inquiry_id'])
            ->find();
        $io_data['quotation_offer']=$post['quotation_detail'];
        $io_data['tax']=$post['tax'];
        $io_data['tax_ratio']=$post['tax_ratio'];
        /*$io_data['freight']=$post['freight'];
        $io_data['install_fee']=$post['install_fee'];*/
        $io_data['time_limit']=$post['time_limit'];
        $io_data['total_price']=$post['total_price'];
        $io_data['status']=1;
        $io_data['offer_money']=$real_money;//抢单费用
        if(!$inquiry_offer){
            //未报价 新增报价明细
            $io_data['mid']=UID;
            $io_data['inquiry_id']=$post['inquiry_id'];
            $io_data['addtime']=time();
            $io_data['order_sn']=DataService::createSequence(10,'INQUIRY');
            Db::name('inquiry_offer')->insert($io_data);
        }else{
            if($inquiry_offer['status']==0){
                //未提交 更新报价
                Db::name('inquiry_offer')->where('id',$inquiry_offer['id'])->update($io_data);
            }else{
                //已报价
                return json(['msg'=>'请不要重复报价'],500);
            }
        }
        //扣除广告币
        if($real_money>0){
            log_account_change(UID,-$real_money,0,'抢单扣除余额',4);
        }
        return json(['msg'=>'报价成功,正在候选'],200);

    }

    /**
     * 我发布的询价
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function mine(){
        $page_size=$this->request->get('page_size',10);
        $page_now=$this->request->get('page_now',1);
        $list=Db::name('inquiry')
            ->where('mid',UID)
            ->field('id,mid,desc,addtime,grab_sheet_end_time,back_type,quotation_detail,status,title')
            ->page($page_now,$page_size)
            ->order('status,id desc')
            ->select();
        foreach ($list as $k=>&$v){
            $v['addtime']=date('Y/m/d H:i:s',$v['addtime']);
            $v['grab_sheet_end_time']=date('Y/m/d H:i:s',$v['grab_sheet_end_time']);
            $v['quotation_detail']=json_decode($v['quotation_detail'],true);
        }
        return json(['msg'=>'success','data'=>$list],200);
    }

    /**
     * 我的抢单列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function my_grab_sheet(){
        $page_size=$this->request->get('page_size',10);
        $page_now=$this->request->get('page_now',1);
        $list=Db::name('inquiry_offer')
            ->alias('io')
            ->join('inquiry i','i.id=io.inquiry_id')
            ->join('store_member m','m.id=i.mid')
            ->field('i.id,i.desc,i.title,i.addtime,i.grab_sheet_end_time,i.quotation_detail,i.status,m.nickname,i.mobile phone,io.status io_status')
            ->where('io.mid',UID)
            ->where('io.status','>',0)
            ->order('addtime desc')
            ->page($page_now,$page_size)
            ->select();
        foreach ($list as $k=>&$v){
            $v['addtime']=date('Y/m/d',$v['addtime']);
            $v['grab_sheet_end_time']=date('Y/m/d H:i:s',$v['grab_sheet_end_time']);
            $v['quotation_detail']=json_decode($v['quotation_detail'],true);
        }
        return json(['msg'=>'success','data'=>$list],200);
    }

    /**
     * 竞价者查看询价详情
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function grab_sheet_detail(){
        //抢单者查看详情
        $inquiry_id=$this->request->get('inquiry_id');
        $inquiry=Db::name('inquiry')
            ->alias('i')
            ->join('inquiry_offer io','io.inquiry_id=i.id and io.mid='.UID)
            ->join('store_member m','m.id=i.mid')
            ->where('i.id',$inquiry_id)
            ->field('m.nickname,m.phone author_phone,m.type member_type,
            i.addtime,i.quotation_detail,i.back_type,i.mid,i.mobile phone,i.order_sn,i.status inquiry_status,
            io.quotation_offer,io.tax,io.freight,io.install_fee,io.tax_ratio,io.time_limit,io.total_price,io.status')
            ->find();
        $inquiry['nickname']=InquiryService::deal_nickname($inquiry['nickname'],$inquiry['member_type'],$inquiry['mid']);

        $inquiry['addtime']=date('Y/m/d',$inquiry['addtime']);
        $inquiry['quotation_detail']=json_decode($inquiry['quotation_detail'],true);
        $inquiry['quotation_offer']=json_decode($inquiry['quotation_offer'],true);

        $inquiry['win_info']=Db::name('inquiry_offer')
            ->alias('io')
            ->join('supplier_info si','si.mid=io.mid')
            ->where('io.inquiry_id',$inquiry_id)
            ->where('io.status',3)
            ->field('io.total_price,si.name')
            ->find();
        return json(['msg'=>'success','data'=>$inquiry]);
    }

    /**
     * 供应商报价对比
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function quotation_comparison(){
        //供应商报价对比
        $inquiry_id=$this->request->get('inquiry_id');
        //查询这条订单的抢单列表
        $offerList=Db::name('inquiry_offer')
            ->alias('io')
            ->join('store_member m','m.id=io.mid')
            ->where('io.inquiry_id',$inquiry_id)
            ->where('io.status','>',0)
            ->field('io.total_price,io.tax,io.freight,io.install_fee,io.mid,io.id,io.inquiry_id,io.status,io.quotation_offer,
            m.nickname,m.phone,m.type member_type,m.id mid')
            ->order('io.total_price')
            ->select();
        foreach ($offerList as &$v){
            $v['quotation_offer']=json_decode($v['quotation_offer'],true);
            $v['nickname']=InquiryService::deal_nickname($v['nickname'],$v['member_type'],$v['mid']);
        }

        $inquiry=Db::name('inquiry')
            ->where('id',$inquiry_id)
            ->field('id,quotation_detail,status,order_sn')
            ->find();
        $inquiry['quotation_detail']=json_decode($inquiry['quotation_detail'],true);

        $data['offerList']=$offerList;
        $data['inquiry']=$inquiry;
        $data['count_offerList']=count($offerList);
        return json(['msg'=>'success','data'=>$data]);
    }

    /**
     * 发布者选择供应商
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function choose_supplier(){
        $inquiry_id=$this->request->get('inquiry_id');
        $offer_id=$this->request->get('offer_id');
        $inquiry=Db::name('inquiry')
            ->where('id',$inquiry_id)
            ->where('status',1)
            ->where('mid',UID)
            ->field('id,status')
            ->find();
        if(!$inquiry){
            return json(['msg'=>'数据异常'],500);
        }
        //订单置为成功 抢单置为成功
        Db::startTrans();
        try{
            Db::name('inquiry')
                ->where('id',$inquiry_id)
                ->setField('status',3);
            Db::name('inquiry_offer')
                ->where('id',$offer_id)
                ->setField('status',3);
            Db::name('inquiry_offer')
                ->where('inquiry_id',$inquiry_id)
                ->where('id','<>',$offer_id)
                ->setField('status',2);
            $inquiry_offer=Db::name('inquiry_offer')
                ->where('id',$offer_id)
                ->field('mid,offer_money')
                ->find();
            //分润
            MemberService::rebate($inquiry_offer['mid'],$inquiry_offer['offer_money'],'您的下级用户['.$inquiry_offer['mid'].']于['.date('Y/m/d H:i:s').']成功中标，您获得分润');
            //TODO::退还未中标的团币
            Db::commit();
            return json(['msg'=>'选择成功']);
        }catch (Exception $e){
            Db::rollback();
            return json(['msg'=>'网络异常,请稍后'],500);
        }

    }

    /**
     * 发布者查看抢单者的报价详情
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function supplier_offer_detail(){
        $inquiry_id=$this->request->get('inquiry_id');
        $offer_id=$this->request->get('offer_id');
        $inquiry=Db::name('inquiry')
            ->alias('i')
            ->join('inquiry_offer io','io.inquiry_id=i.id and io.id='.$offer_id)
            ->join('store_member m','m.id=io.mid')
            ->where('i.id',$inquiry_id)
            ->field('m.nickname,m.phone,m.type member_type,
            i.quotation_detail,i.back_type,
            io.quotation_offer,io.tax,io.freight,io.install_fee,io.tax_ratio,io.time_limit,io.total_price,io.status,io.mid,io.addtime')
            ->find();

        $inquiry['nickname']=InquiryService::deal_nickname($inquiry['nickname'],$inquiry['member_type'],$inquiry['mid']);

        $inquiry['addtime']=date('Y/m/d',$inquiry['addtime']);
        $inquiry['quotation_detail']=json_decode($inquiry['quotation_detail'],true);
        $inquiry['quotation_offer']=json_decode($inquiry['quotation_offer'],true);
        return json(['msg'=>'success','data'=>$inquiry]);
    }

    /**
     * 询价导航数据
     * @return \think\response\Json
     */
    function nav_data(){

        //查询我抢了单的
        $inquiry_offer=Db::name('inquiry_offer')
            ->where('mid',UID)
            ->where('status','<>',0)
            ->column('inquiry_id');

        $db=Db::name('inquiry')
            ->where('status',1)
            ->where('grab_sheet_end_time','>',time())
            ->where('mid','<>',UID);
        if($inquiry_offer){
            $db->where('id','not in',$inquiry_offer);
        }
        //查询正在抢单的数量
        $data['demand_num']=$db->count();

        //查询我参与了的需求
        $demand_offer=Db::name('demand_offer')
            ->where('mid',UID)
            ->column('demand_id');

        $db=Db::name('member_demand')
            ->where('status',1)
            ->where('endtime','>',time())
            ->where('mid','<>',UID);
        if($inquiry_offer){
            $db->where('id','not in',$demand_offer);
        }
        //查询正在抢单的数量
        $data['requirement_num']=$db->count();
        /*//查询我发布的数量
        $data['push_num']=Db::name('inquiry')
            ->where('mid',UID)
            ->count();
        //查询我已抢的数量
        $data['offer_num']=Db::name('inquiry_offer')
            ->where('mid',UID)
            ->where('status','<>',0)
            ->count();*/
        return json(['msg'=>'success','data'=>$data]);
    }

    /**
     * 删除询价
     * @return \think\response\Json
     */
    function del(){
        //询价ID
        $inquiry_id=$this->request->get('inquiry_id');
        Db::transaction(function() use ($inquiry_id){
            Db::name('inquiry')
                ->where('id',$inquiry_id)
                ->where('mid',UID)
                ->delete();
            //删除抢单记录
            Db::name('inquiry_offer')
                ->where('inquiry_id',$inquiry_id)
                ->delete();
        });
        return json(['msg'=>'删除成功'],200);
    }

}